﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tookit.Mvvm.Navigation.Message;
using Tookit.Mvvm.Navigation.Models;
using Tookit.Mvvm.Navigation.Serves;

namespace Tookit.Mvvm.Navigation.ViewModels
{
    public partial class LoginViewModel:ObservableObject
    {
        [ObservableProperty]
        string m_passWord;

        [ObservableProperty]
        string m_account;

        UserSession _userSession;

        DbContext _dbContext;
        public LoginViewModel(UserSession userSession, DbContext dbContext)
        {
            _userSession = userSession;
            _dbContext = dbContext;
        }

        [RelayCommand]
        void Login()
        {
            User user=new User() { Account = Account,Password=PassWord };

            _userSession.CurrentUser = user;
            if (_dbContext.FindUser(user))
            {
                //登录后切换
                WeakReferenceMessenger.Default.Send(new LoginMessage(user));
            }

        }
    }
}
